package com.zttek.videoShareProject.modules.web;


import com.zttek.videoShareProject.common.json.Result;
import com.zttek.videoShareProject.modules.model.Keyword;
import com.zttek.videoShareProject.modules.service.IKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CBY
 * @since 2018-07-03
 */
@Controller
@RequestMapping("/keyword")
public class KeywordController {
    @Autowired
    private IKeywordService iKeywordService;

    @RequestMapping("/keyWord")
    public ModelAndView initKeyWord(){
        return new ModelAndView("/keyWord/keyWord");
    }

    @RequestMapping("/getKeyWordList")
    @ResponseBody
    public Result getKeyWordList(){
        Result result=new Result();
        List<Keyword> list;
        if((list=iKeywordService.getKeyWordList())!=null){
            for (Keyword item:list
                 ) {
                System.out.println(item.toString());

            }
            result.setSuccess(true);
            result.add("keyWordList",list);
        }else{
            result.setSuccess(false);
            result.setMsg("初始化失败");
        }
        return result;
    }

    @RequestMapping("/addKeyWord")
    @ResponseBody
    public Result addKeyWord(@RequestParam(value = "keyWord")String keyWorrd){
        Result result=new Result();
        if(iKeywordService.addKeyWord(keyWorrd)){
            result.setSuccess(true);
        }else {
            result.setSuccess(false);
        }
        return result;
    }
    @RequestMapping("/deleteKeyWord")
    @ResponseBody
    public Result deleteKeyWord(@RequestParam(value = "id")Long id){
        Result result=new Result();
        if(iKeywordService.deleteKeyWord(id)){
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
	
}
